/*
ID: icerupt1
PROG: concom
LANG: C++11
*/

/*
 * cc循环多次做类似floyd有点乱搞。
 * 最好的方法可能是松弛的思想，一旦新的i control j，就去更新与之相关的边。
*/
#include <fstream>
#include <iostream>

std::ifstream fin {"concom.in" };
std::ofstream fout{"concom.out"};

int const maxn = 102;
bool vis[maxn][maxn][maxn];
bool control[maxn][maxn];
int da[maxn][maxn];
int n, m;

int main()
{
	fin >> n;
	for (int i = 0, x, y; i < n; i++) {
		fin >> x >> y;
		if (da[x-1][y-1]) std::cout << "hello world\n";
		fin >> da[x-1][y-1];
		m = std::max(m, std::max(x, y));
	}

	for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++) {
			if (da[i][j] > 50) control[i][j] = true;
			if (control[i][j]) continue;
			int t = da[i][j];
			for (int k = 0; k < m; k++)
				if (control[i][k] && i != k) t += da[k][j];
			if (t > 50) control[i][j] = true;
		}
//	for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) std::cout << da[i][j] << ' '; std::cout << '\n'; }

	for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++)
			if (i != j && control[i][j]) {
				std::cout << i + 1 << ' ' << j + 1 << '\n';
				fout << i + 1 << ' ' << j + 1 << '\n';
			}
}
